<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
	"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<meta http-equiv="Content-type" content="text/html; charset=utf-8">
	<link rel="stylesheet" href="css/reset.css" type="text/css" media="screen" title="no title" charset="utf-8">
	<script src="js/jquery-1.4.2.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/tomcat-6.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript" charset="utf-8">

		$(document).ready(function(){
			var deployedList = $("#deployedList");
			$(TOMCAT.deployed()).each(function(index){
				deployedList.append(getDeployment(this));
			});
			
		});
		
		function getState(deployed){
			var node = $(document.createElement("span")).addClass("state");
			node.append(deployed.state)
			if(deployed.state == "running"){
				node.addClass("success");
			}else{
				node.addClass("error");
			}
			return node;
		}
		
		function getActions(deployed){
			var actionsNode = $(document.createElement("span")).addClass("actions");
			$(["Start", "Stop", "Restart"]).each(function(){
				var action = this;
				var node = $(document.createElement("a")).html(action.toString() + "&nbsp;");
				node.click(function(){
					preformAction(deployed.context, action)
				});
				actionsNode.append(node);
			});
			return actionsNode;
		}
		
		function getContext(deployed){
			var contextNode = $(document.createElement("span")).addClass("context");
			var link = $(document.createElement("a")).append(deployed.context.toString()).attr({
				href: deployed.url,
				target: "_blank"
			});
			contextNode.append(link);
			return contextNode;
		}
		
		function getDeployment(deployed){
			var item = $(document.createElement("li")).addClass("deployment");
			item.append(getState(deployed));
			item.append(getActions(deployed));
			item.append(getContext(deployed));
			return item;
		}
		
		function preformAction(context, action){
			console.log("Preforming action: " + action + " for context: " + context);
		}

	</script>
	<style type="text/css" media="screen">
		.server{
			padding-left: 0;
		}
	
		.deployment{
			white-space: nowrap;
			list-style-type: none;
			clear:both;
		}
		
		.state{
			padding: 0.2em;
			width: 4em;
			display: block;
			float: left;
			text-align: center;
			margin-bottom:0.1em;
		}
		
		.actions, .context{
			margin:0px 0px 0px 10px;
		}
		
		.actions a{
			text-decoration: none;
		}
	</style>
</head>
<body>
	<h3>http://localhost:8080/</h3>
	<ul class="server" id="deployedList">

	</ul>
</body>
</html>